home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 4 / The 640 Meg Shareware Studio CD-ROM Volume IV (Data Express)(1994).ISO / clang / dvector.zip / SINGEN.C < prev    next >
C/C++ Source or Header  |  1993-08-11  |  2KB  |  70 lines

  1. /* written by Justin Newman      date: July 4th, 1993 */
  2. /* generates sine and cosine tables */
  3.  
  4. #include <stdio.h>
  5. #include <math.h>
  6.  
  7. #define NUM    256
  8. #define NUMB 8
  9.  
  10. int
  11. main()
  12. {
  13.      int i,i1,stuff,a;
  14.      FILE *fp;
  15.  
  16.      if ((fp=fopen("sincos.h","w+"))==NULL)
  17.         {
  18.             printf("file error:  can't open file SINCOS.H\n");
  19.             return -1;
  20.         }
  21.  
  22.      /* message */ printf("creating SINCOS.H\n");
  23.  
  24.      fprintf(fp,"/* sincos.h: */\n");
  25.      fprintf(fp,"/*   sine and cosine tables   use: sintbl[Θ] = sin Θ * %d */\n",NUM);
  26.      fprintf(fp,"/*   there are 360 entries for each table */\n");
  27.      fprintf(fp,"\n");
  28.      fprintf(fp,"#ifndef _SINCOS_H\n");
  29.      fprintf(fp,"#define _SINCOS_H\n");
  30.      fprintf(fp,"\n");
  31.      fprintf(fp,"#define NUM %d\n",NUM);
  32.      fprintf(fp,"#define NUMB %d\n",NUMB);
  33.      fprintf(fp,"\n");
  34.      fprintf(fp,"int sintbl[]={   /* sine table */\n");
  35.      for (i=0;i<36;i++)
  36.         {
  37.             fprintf(fp,"   ");
  38.             for (i1=0;i1<10;i1++)
  39.              {
  40.                 a=i*10+i1;
  41.                 stuff=(int)(ceil(sin((double)a*(3.141592654/180))*NUM));
  42.                 fprintf(fp,"%6d,",stuff);
  43.              }
  44.             fprintf(fp,"\n");
  45.         }
  46.      fprintf(fp,"}; /* end sintbl */\n");
  47.      fprintf(fp,"\n");
  48.      fprintf(fp,"int costbl[]={   /* cosine table */\n");
  49.      for (i=0;i<36;i++)
  50.         {
  51.             fprintf(fp,"   ");
  52.             for (i1=0;i1<10;i1++)
  53.              {
  54.                 a=i*10+i1;
  55.                 stuff=(int)(ceil(cos((double)a*(3.141592654/180))*NUM));
  56.                 fprintf(fp,"%6d,",stuff);
  57.              }
  58.             fprintf(fp,"\n");
  59.         }
  60.      fprintf(fp,"}; /* end costbl */\n");
  61.      fprintf(fp,"\n");
  62.      fprintf(fp,"#endif\n");
  63.      fclose(fp);
  64.  
  65.      /* message */ printf("done\n");
  66.  
  67.      return 0;
  68. }
  69.  
  70.